<template>
	<div v-if="visible" class="message-box-overlay">
		<div class="message-box">
			<div class="message-box-header">
				<h3>{{ title }}</h3>
			</div>
			<div class="message-box-content">
				<p>{{ message }}</p>
			</div>
			<div class="message-box-footer">
				<button @click="handleConfirm">{{ confirmButtonText }}</button>
				<button @click="handleCancel">{{ cancelButtonText }}</button>
			</div>
		</div>
	</div>
</template>

<script lang="ts">
	import { defineComponent, ref } from 'vue'

	export default defineComponent({
		name: 'MessageBox',
		props: {
			title: {
				type: String,
				default: '提示',
			},
			message: {
				type: String,
				required: true,
			},
			confirmButtonText: {
				type: String,
				default: '确定',
			},
			cancelButtonText: {
				type: String,
				default: '取消',
			},
		},
		emits: ['confirm', 'cancel'],
		setup(props, { emit }) {
			const visible = ref(true)

			const handleConfirm = () => {
				emit('confirm')
				visible.value = false
			}

			const handleCancel = () => {
				emit('cancel')
				visible.value = false
			}

			return {
				visible,
				handleConfirm,
				handleCancel,
			}
		},
	})
</script>

<style scoped>
	.message-box-overlay {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 1000;
	}

	.message-box {
		background-color: white;
		padding: 20px;
		border-radius: 8px;
		max-width: 600px;
		width: 100%;
	}

	.message-box-header h3 {
		margin: 0;
		font-size: 40px;
		color: #000;
	}

	.message-box-content {
		margin: 20px 0;
		font-size: 35px;
		color: #000;
	}

	.message-box-footer {
		display: flex;
		justify-content: flex-end;
	}

	.message-box-footer button {
		margin-left: 10px;
		padding: 12px 20px;
		border: none;
		border-radius: 4px;
		cursor: pointer;
		font-size: 25px;
	}

	.message-box-footer button:first-child {
		background-color: #409eff;
		color: white;
	}

	.message-box-footer button:last-child {
		background-color: #f56c6c;
		color: white;
	}
</style>
